﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class WeaponFire : Weapon
{
    public GameObject bulletPart;
    public GameObject bullet;
    public int attack;

    public override void AttackBegin()
    {
        StartCoroutine(Attack());
    }

    public override void AttackEnd()
    {

    }

    IEnumerator Attack()
    {
        yield return new WaitForSeconds(0.1f);

        GameObject go = Instantiate(bulletPart);
        GameObject obj = Instantiate(bullet);

        go.transform.position = role.transform.position + new Vector3(0,1f,0) + role.transform.forward * 0.5f;
        obj.transform.position = role.transform.position + new Vector3(0, 1f, 0) + role.transform.forward * 0.5f;

        go.transform.forward = role.transform.forward;

        FireBullet fire = obj.GetComponent<FireBullet>();
        fire.weapon = this;
        fire.vt = role.transform.forward;

        Destroy(go, 5);
        Destroy(obj, 5);
    }
    public void Hit(Collider collider)
    {
        if (onHit != null)
        {
            onHit.Invoke(collider, attack);
        }
    }

}
